package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseEventSubscriptionResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.EventSubscriptionResponse;
import java.time.OffsetDateTime;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.EventSubscriptionsApi")
public class EventSubscriptionsApi {
    private ApiClient apiClient;

    public EventSubscriptionsApi() {
        this(new ApiClient());
    }

    @Autowired
    public EventSubscriptionsApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get a single event subscription
     *
     * <p><b>200</b> - Indicates the event subscription exists and is returned.
     * <p><b>404</b> - Indicates the requested event subscription does not exist.
     * @param eventSubscriptionId The eventSubscriptionId parameter
     * @return EventSubscriptionResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public EventSubscriptionResponse getEventSubscription(String eventSubscriptionId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'eventSubscriptionId' is set
        if (eventSubscriptionId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'eventSubscriptionId' when calling getEventSubscription");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("eventSubscriptionId", eventSubscriptionId);
        String path = UriComponentsBuilder.fromPath("/runtime/event-subscriptions/{eventSubscriptionId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<EventSubscriptionResponse> returnType = new ParameterizedTypeReference<EventSubscriptionResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of event subscriptions
     *
     * <p><b>200</b> - Indicates the requested event subscriptions were returned.
     * <p><b>400</b> - Indicates an illegal value has been used in a url query parameter. Status description contains additional details about the error.
     * @param id Only return event subscriptions with the given id
     * @param eventType Only return event subscriptions with the given event type
     * @param eventName Only return event subscriptions with the given event name
     * @param activityId Only return event subscriptions with the given activity id
     * @param executionId Only return event subscriptions with the given execution id
     * @param processInstanceId Only return event subscriptions part of a process with the given id
     * @param processDefinitionId Only return event subscriptions with the given process definition id
     * @param scopeId Only return event subscriptions part of a scope with the given id
     * @param scopeDefinitionId Only return event subscriptions with the given scope definition id
     * @param createdBefore Only return event subscriptions which are created before the given date.
     * @param createdAfter Only return event subscriptions which are created after the given date.
     * @param tenantId Only return event subscriptions with the given tenant id.
     * @param sort Property to sort on, to be used together with the order.
     * @return DataResponseEventSubscriptionResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseEventSubscriptionResponse listEventSubscriptions(String id, String eventType, String eventName, String activityId, String executionId, String processInstanceId, String processDefinitionId, String scopeId, String scopeDefinitionId, OffsetDateTime createdBefore, OffsetDateTime createdAfter, String tenantId, String sort) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/runtime/event-subscriptions").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", id));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "eventType", eventType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "eventName", eventName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityId", activityId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "executionId", executionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processInstanceId", processInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processDefinitionId", processDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "scopeId", scopeId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "scopeDefinitionId", scopeDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdBefore", createdBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdAfter", createdAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", sort));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseEventSubscriptionResponse> returnType = new ParameterizedTypeReference<DataResponseEventSubscriptionResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
